//
//  BookDetailViewController.swift
//  BookStore2.0
//
//  Created by hw on 2022/5/31.
//

import UIKit

class BookDetailViewController: UIViewController,UIPopoverPresentationControllerDelegate{

    var ID: String!
    
    var Info:[[String:AnyObject]]?
    
    @IBOutlet weak var img: UIImageView!
    @IBOutlet weak var author: UILabel!
    @IBOutlet weak var bookname: UILabel!
    @IBOutlet weak var id: UILabel!
    @IBOutlet weak var press: UILabel!
    @IBOutlet weak var price: UILabel!
    
    @IBOutlet weak var descriptionLabel: UITextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        InitialInfo(bookid: ID)
        // Do any additional setup after loading the view.
    }
    func InitialInfo(bookid:String)
    {
        Info=DB1.selectBookByid(id:bookid)
        bookname.text=Info?[0]["title"] as? String
        img.image=DB1.imgSet[bookid]
        descriptionLabel.text=Info?[0]["description"] as? String
        author.text=Info?[0]["author"] as? String
        press.text=Info?[0]["publisher"] as? String
        id.text=bookid
        let a=(Info![0]["price"] as! NSNumber).floatValue
        price.text="RMB:\(a)"
    }
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let nextvc=segue.destination as! ConfirmBuyBookViewController
        nextvc.confirmbookimg=img
        nextvc.bookcopy.id=ID
        nextvc.bookcopy.title=bookname.text!
        nextvc.bookcopy.eachprice=(Info![0]["price"] as! NSNumber).floatValue
        if segue.identifier=="buy" {
            nextvc.Flag=true
        }
        else {
            nextvc.Flag=false
        }
    }
}
